<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 给定一个字符串 s ，请你找出其中不含有重复字符的 最长 
    /* 
      分析：
        1. abcabcbb => abc; bbbbb => b；pwwkew，=> wke
        2. 双指针遍历， 拿到所有子串
    */
    const lengthOfLongestSubstring = function (s) {
      // 如果为空，返回0
      if (!s) return 0
      if (s === ' ') return 1
      let arr = []
      let long = 0
      let longStr = ''
      for (let i = 0; i < s.length; i++) {
       for (let j = i + 1; j <= s.length; j++) {
        let str = s.slice(i, j) // 拿到所有子串
        let flag = isRepeatStr(str)
        if (!flag) {
          longStr = str.length > longStr.length ? str : longStr
          long = str.length > longStr.length ? longStr.length : long
        }
       }
      }
      return long
    }
    const isRepeatStr = function (str) {
      for (let i = 0; i < str.length; i++) {
        let subStr = str[i]
        for (let j = i + 1; j < str.length; j++) {
          if (str[i] === str[j]) {
            return true
          }
        }
      }
      return false
    }
    // console.log(lengthOfLongestSubstring('abcabcbb'), 'lengthOfLongestSubstring');
    // console.log(lengthOfLongestSubstring('pwwkew'), 'lengthOfLongestSubstring');
    // console.log(lengthOfLongestSubstring('pwwkew'), 'lengthOfLongestSubstring');
    console.log(lengthOfLongestSubstring('c'), 'lengthOfLongestSubstring');
  </script>
</body>
</html>